using System;
using System.Windows.Forms;

namespace pal.SvnConf.GUI
{
    public partial class ChangePasswordControl : UserControl
    {
        private PasswordChangeHandler _passwordChangeHandler;
        private string _userName;

        public ChangePasswordControl(string userName)
        {
            _userName = userName;
            InitializeComponent();
        }

        private void OnChangePasswordClick(object sender, EventArgs e)
        {
            if (_txtNewPassword.Text != _txtConfirmPassword.Text)
            {
                MessageBox.Show("Passwords don't match");
                return;
            }

            if (_passwordChangeHandler != null)
                _passwordChangeHandler(_userName, _txtNewPassword.Text);
        }

        public event PasswordChangeHandler OnPasswordChange
        {
            add { _passwordChangeHandler += value; }
            remove { _passwordChangeHandler -= value; }
        }
    }

    public delegate void PasswordChangeHandler(string userName, string password);
}